﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Common.UI.Report.Views
{
    /// <summary>
    /// Interaction logic for ReportWindow.xaml
    /// </summary>
    public partial class ReportWindow : Window
    {
        private string reportPath;
        private string dataSourceName;
        private object data;
        private List<ReportParameters> parameters;
        private bool allowPrint;
        private bool allowExport;

        public ReportWindow()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(ReportWindow_Loaded);
            this.reportViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);

        }

        public ReportWindow(string reportPath, string dataSourceName, object data, List<ReportParameters> parameters, bool allowExport, bool allowPrint)
            : this()
        {
            this.reportPath = reportPath;
            this.dataSourceName = dataSourceName;
            this.data = data;
            this.parameters = parameters;
            this.allowExport = allowExport;
            this.allowPrint = allowPrint;

            this.reportViewer.ShowExportButton = allowExport;
            this.reportViewer.ShowPrintButton = allowPrint;


            this.reportViewer.LocalReport.ReportPath = reportPath;
            this.reportViewer.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource(dataSourceName, data));
            foreach (var item in parameters)
            {
                this.reportViewer.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter(item.Name, item.Value));
            }
        }

        void ReportWindow_Loaded(object sender, RoutedEventArgs e)
        {
            this.reportViewer.RefreshReport();
        }
    }
}
